<html>
    <?php
    echo $this->render("/common/header.phtml");
    ?>
    <script>
        function updatePlace(id){
            var placeName = document.getElementById('placeName').value;
            var placePhone = document.getElementById('placePhone').value;
            var baseUrl = <?php echo '"' . $this->doupdate . '"' ?>             
            var a = baseUrl+"?id="+id+"&placeName="+placeName+"&placePhone="+placePhone+"&method=updatePlace";            
            ajax.get(a,null,function(f){
                alert(f);
            },null);  
        }

        function updateAddress(id){            
            var site = document.getElementById('site');
            site = site.options[site.selectedIndex].id;             
            var info = document.getElementById('info').value;
            info = encodeURIComponent(info);
            var addressNumber = document.getElementById('addressNumber').value;
            var addressStreet = document.getElementById('addressStreet').value;
            addressStreet = encodeURIComponent(addressStreet);
            var addressLon = document.getElementById('addressLon').value;
            addressLon = encodeURIComponent(addressLon);
            var addressLat = document.getElementById('addressLat').value;
            addressLat = encodeURIComponent(addressLat);
            var addressDescription = document.getElementById('addressDescription').value;
            addressDescription = encodeURIComponent(addressDescription);
            var addressWard  = document.getElementById('addressWard').value;
            addressWard =encodeURIComponent(addressWard);
            var baseUrl = <?php echo '"' . $this->doupdate . '"' ?>             
            var a = baseUrl+"?id="+id+
                "&site="+site+
                "&info="+info+
                "&addressNumber="+addressNumber+
                "&addressStreet="+addressStreet+
                "&addressWard="+addressWard+
                "&addressLon="+addressLon+
                "&addressLat="+addressLat+
                "&addressDescription="+addressDescription+
                "&method=updateAddress";
            ajax.get(a,null,function(f){
                alert(f);
                
            },null);              
             
        }
        
        function updateMenu(id){
            var menuDetail = document.getElementById('menuDetail').value;   
            menuDetail = encodeURIComponent(menuDetail);
            var baseUrl = <?php echo '"' . $this->doupdate . '"' ?>             
            var a = baseUrl+"?id="+id+"&menuDetail="+menuDetail+"&method=updateMenu";
            ajax.get(a,null,function(f){
                alert(f);
            },null);  
            
        }
        
        function updateReview(id){            
            var reviewContent = document.getElementById('reviewContent').value;  
            reviewContent = encodeURIComponent(reviewContent);
            var imageLinks = document.getElementById('imageLinks').value;   
            imageLinks = encodeURIComponent(imageLinks);
            var baseUrl = <?php echo '"' . $this->doupdate . '"' ?>             
            var a = baseUrl+"?id="+id+"&reviewContent="+reviewContent+"&imageLinks="+imageLinks+"&method=updateReview";
            ajax.get(a,null,function(f){
                alert(f);
            },null);  
        }
        
        function updateMap(id){
            var mapLink = document.getElementById('mapLink').value;           
            var baseUrl = <?php echo '"' . $this->doupdate . '"' ?>             
            var a = baseUrl+"?id="+id+"&mapLink="+mapLink+"&method=updateMap";
            ajax.get(a,null,function(f){
                alert(f);
            },null);  
        }
        
        function updateType(id){
            var cbox = document.getElementById('type');
            var typeId = cbox.options[cbox.selectedIndex].id;            
            var baseUrl = <?php echo '"' . $this->doupdate . '"' ?>             
            var a = baseUrl+"?id="+id+"&type="+typeId+"&method=updateType";
            ajax.get(a,null,function(f){
                alert(f);
            },null);  
            
        }
        

    </script>
    <body>
        <div id="error" > </div>
        <?php
        echo $this->render("/common/topMenu.phtml");
        ?>
        <?php
        if ($this->onDone) {
            echo '<b>Insert done</b>';
        }
        ?>
        <form action="doinsert" method="POST">
            <br>
            <div id="intro" >
                <h3 class="lbDesc">Loại quán</h3>                
                <select id="type" name="type">
                    <?php
                    if ($this->allType != null) {
                        foreach ($this->allType as $item) {
                            $id = $item['id'];
                            if ($id == $this->type) {
                                echo '<option selected=true id=' . $id . '>' . $item['name'] . '</option>';
                            } else {
                                echo '<option id=' . $id . '>' . $item['name'] . '</option>';
                            }
                        }
                    }
                    ?>
                </select>
                <input type="button" value="Update Type" onclick="updateType(<?php echo $this->place['id'] ?>)" />
            </div>
            <hr>
            <h3 class="lbDesc">General</h3>
            <div id="detail">
                <table id="gradient-style">
                    <tr>
                        <th>Name place</th>
                        <th>Phone number</th>
                        <th>Updates</th>
                    </tr>
                    <tr>
                        <td><input type="text" name="placeName" id="placeName" value="<?php echo $this->place['name'] ?>"/></td>
                        <td><input type="text" name="placePhone"  id="placePhone" value="<?php echo $this->place['phoneNumber'] ?>" /></td>
                        <td><input type="button" value="Update Name&Phone" onclick="updatePlace(<?php echo $this->place['id'] ?>)" /></td>
                    </tr>                    
                </table>
            </div>
            <div id="address">               
                <table id="gradient-style" style="width: 90%">
                    <tr>
                        <th>Info</th>
                        <th>Lon</th>
                        <th>Lat</th>     
                        <th>Description</th>    
                        <th>Updates</th>    
                    </tr>
                    <tr>
                        <td><input type="text" name="addressNumber" id="info" value="<?php echo $this->address['info'] ?>"/></td>
                        <td hidden="1"><input type="text" name="addressNumber" id="addressNumber" value="<?php echo $this->address['number'] ?>"/></td>
                        <td>
                            <select id="site" name="site">
                                <?php
                                if ($this->allSite != null) {
                                    foreach ($this->allSite as $item) {
                                        $id = $item['id'];
                                        if ($id == $this->address['site']) {
                                            echo '<option selected=true id=' . $id . '>' . $item['name'] . '</option>';
                                        } else {
                                            echo '<option id =' . $id . '>' . $item['name'] . '</option>';
                                        }
                                    }
                                }
                                ?>
                            </select>
                        </td>
                        <td><input type="text" name="addressStreet"  id="addressStreet"value="<?php echo $this->address['street'] ?>"/></td>
                        <td><input type="text" name="addressWard"  id="addressWard"value="<?php echo $this->address['ward'] ?>"/></td>
                        <td><input type="text" name="addressLon"  id="addressLon"value="<?php echo $this->address['lon'] ?>"/></td>
                        <td><input type="text" name="addressLat" id="addressLat" value="<?php echo $this->address['lat'] ?>"/></td>
                        <td><textarea id="addressDescription" cols="40" rows ="5" style="width: 100%" name="addressDescription"><?php echo $this->address['description'] ?></textarea></td>
                        <td><input type="button" value="Update Address" onclick="updateAddress(<?php echo $this->address['id'] ?>)" /></td>
                    </tr>                    
                </table>


            </div> 
            <hr>
            <div id="menu">
                <b class="lbDesc">Menu</b>
                <br>
                <textarea id="menuDetail" cols="40" rows ="5" style="width: 100%" name="menuDetail" ><?php echo $this->menu['menuDetail'] ?></textarea>
                <input type="button" value="Update Menu" onclick="updateMenu(<?php echo $this->menu['id'] ?>)" />
            </div> 
            <hr>
            <div id="review">
                <b class="lbDesc">Review</b>
                <br>
                <textarea id="reviewContent" cols="40" rows ="5" style="width: 100%" name="reviewContent"><?php echo $this->review['content'] ?></textarea>
                <b class="lbDesc">Image</b>
                <br>
                <textarea id="imageLinks" cols="40" rows ="5" style="width: 100%"  name="imageLinks" ><?php echo $this->review['imageList'] ?></textarea>
                <input type="button" value="Update Review" onclick="updateReview(<?php echo $this->review['id'] ?>)" />
            </div>
            <hr>
            <div id="map">
                <b class="lbDesc">Map</b>
                <br>
                <input type="text" name="mapLink"  id="mapLink" style="width: 100%" value="<?php echo $this->map['link'] ?>"/><br>
                <input type="button" value="Update Map" onclick="updateMap(<?php echo $this->map['id'] ?>)" />
            </div>
            <hr>

            <input type="submit" value="Insert new this Place" style="padding-left: 0.5em " >
        </form>
    </body>
</html>
